﻿// -----------------------------------------------------------------------
// <copyright file="CustomSlider.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.ControlBuilders
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;
    using Gui.ThemeEngine;
    
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class CustomSlider : BaseControl
    {
        /// <summary>
        /// Create the custom control
        /// </summary>
        /// <param name="controlProperties">The Xml node that contains the control properties</param>
        /// <returns>Returns custom control</returns>
        public Controls.MetalSlider GetControl(XmlNode controlProperties)
        {
            Controls.MetalSlider customSlider = new Controls.MetalSlider();

            // Apply common properties
            this.BuildControl(controlProperties, customSlider as Control);

            // Apply specific control properties
            customSlider.Name = PropertyProvider.GetValue(controlProperties, "command", "slider");
            customSlider.DrawFocusRectangle = PropertyProvider.GetValue(controlProperties, "drawFocusRectangle", false);

            if (PropertyProvider.GetValue(controlProperties, "orientation", "Horizontal") == "Horizontal")
            {
                customSlider.Orientation = Orientation.Horizontal;
            }
            else
            {
                customSlider.Orientation = Orientation.Vertical;
            }

            customSlider.BackColor = PropertyProvider.GetValue(controlProperties, "backColor");

            // Tag property (used for equalizer)
            customSlider.Tag = PropertyProvider.GetValue(controlProperties, "index", -1);
            if (Convert.ToInt32(customSlider.Tag) != -1)
            {
                customSlider.Name += customSlider.Tag;
                customSlider.Maximum = 150;
                customSlider.Minimum = -150;
            }

            // Slider bar
            XmlNode bar = controlProperties.SelectSingleNode("Bar");
            customSlider.BarInnerColor = PropertyProvider.GetValue(bar, "innerColor");
            customSlider.BarOuterColor = PropertyProvider.GetValue(bar, "outerColor");
            customSlider.BarPenColor = PropertyProvider.GetValue(bar, "penColor");

            // Elapsed side
            XmlNode elapsed = controlProperties.SelectSingleNode("Elapsed");
            customSlider.ElapsedInnerColor = PropertyProvider.GetValue(elapsed, "innerColor");
            customSlider.ElapsedOuterColor = PropertyProvider.GetValue(elapsed, "outerColor");

            // Thumb button
            XmlNode thumb = controlProperties.SelectSingleNode("Thumb");
            customSlider.ThumbInnerColor = PropertyProvider.GetValue(thumb, "innerColor");
            customSlider.ThumbOuterColor = PropertyProvider.GetValue(thumb, "outerColor");
            customSlider.ThumbPenColor = PropertyProvider.GetValue(thumb, "penColor");
            Size thumbSize = new Size();
            thumbSize.Width = PropertyProvider.GetValue(thumb, "thumbRoundRectWidth", 8);
            thumbSize.Height = PropertyProvider.GetValue(thumb, "thumbRoundRectHeight", 8);
            customSlider.ThumbRoundRectSize = thumbSize;
            customSlider.ThumbSize = PropertyProvider.GetValue(thumb, "thumbSize", 10);
            customSlider.ForeColor = Color.Black;

            if (PropertyProvider.GetValue(controlProperties, "dataSource", string.Empty) != string.Empty)
            {
                customSlider.DataBindings.Add("Value", Metal.Data.DataStorage.Table, "TrackBarValue");
            }

            return customSlider;
        }

        /// <summary>
        /// Apply common properties
        /// </summary>
        /// <param name="control">The Xml node that contains our control properties</param>
        /// <param name="customControl">The custom control that will be created</param>
        public override void BuildControl(System.Xml.XmlNode control, System.Windows.Forms.Control customControl)
        {
            base.BuildControl(control, customControl);
        }
    }
}
